﻿using System;
using System.Collections.Generic;
using System.Text;
using ZX.SYS.Library;
using ZX.BLL.Extend;
using ZX.DBModule;
using System.IO;
using ZX.Common;
using System.Data;
using ZX.DAL.DBExtend;
using System.Net;
using System.Web;
using System.Configuration;

namespace ZX.SYS.Bussiness
{
    public class MmsProccess : BLL.Extend.BaseBussnies
    {
        public static readonly string mmsUser = ConfigurationManager.AppSettings["mmsUname"].ToString();
        public static readonly string mmsPass = ConfigurationManager.AppSettings["mmsUpass"].ToString();

        /// <summary>
        /// 彩信记录
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="pur">文件夹及历时</param>
        /// <param name="userid">操作者</param>
        /// <returns>操作成功与否</returns>
        public bool insert(string title, string pur, Guid userid)
        {
            MmsMessage mmb = new MmsMessage();
            mmb.mmid = Guid.NewGuid();
            mmb.AddTime = DateTime.Now;
            mmb.AddUser = userid;
            mmb.purtimes = pur;
            mmb.mtitle = title;
            BaseBussnies bmmb = new BaseBussnies(mmb);
            return  bmmb.Insert();
        }

        /// <summary>
        /// 彩信修改
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="pur">文件夹及历时</param>
        /// <param name="userid">操作者</param>
        /// <returns>操作成功行数</returns>
        public int editmms(Guid mid, string title, string pur)
        {
            DbSql dq = new DbSql();
            string sql = "update MmsMessage set mtitle='" + title + "',purtimes='" + pur + "' where mmid='" + mid.ToString() + "' ";
            return dq.ExecuteSql(sql);
        }

        public DataTable getmmsmessage(Guid id)
        {
            DbSql dq = new DbSql();
            string sql = "SELECT [mmid],[mtitle],[purtimes],[AddUser],[AddTime] FROM [MmsMessage] where mmid='" + id + "'";
            return dq.ExecuteQuery(sql);
        }

        public DataTable getmmsifexist(string str)
        {
            DbSql dq = new DbSql();
            string sql = "SELECT mmid FROM [MmsMessage] where purtimes like '" + str + "%' ";
            return dq.ExecuteQuery(sql);
        }

        public bool RecMMS(string sid, string phone, string con)
        {
            MmsBack mb = new MmsBack();
            mb.mmbid = Guid.NewGuid();
            mb.bphone = phone;
            mb.bcontent = con;
            mb.kuozhan = sid;
            mb.backtime = DateTime.Now;
            BaseBussnies bb = new BaseBussnies(mb);
            return bb.Insert();
        }

        public string getmmsfilename(string mmsid)
        {
            DbSql dq = new DbSql();
            string sql = "SELECT purtimes FROM [MmsMessage] where mmid='" + mmsid + "' ";
            DataTable dt= dq.ExecuteQuery(sql);
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0][0].ToString().Split(';')[0];
            }
            else
                return "";
        }

        public bool insertMmsSend(Guid adduser,string mmid,string sendphone,string xmln,string txtn,string status,string bh)
        {
            MmsSend ms = new MmsSend();
            ms.mmsid = Guid.NewGuid();
            ms.AddTime=DateTime.Now;
            ms.AddUser=adduser;
            ms.mmid = new Guid(mmid);
            ms.sendphone = sendphone;
            ms.sendXML = xmln;
            ms.backtxt = txtn;
            ms.sendstatus = status;
            ms.pici = bh;
            BaseBussnies bb = new BaseBussnies(ms);
            return bb.Insert();
        }

        public DataTable getmq400detail(Guid id)
        {
            string sql = @"SELECT
      [mq4id]
      ,[comeintime]
      ,[comename]
      ,[comerole]
      ,[company]
      ,[cphone]
      ,[cfrom]
      ,[crequery]
      ,[creqtype]
      ,[recname]
      ,[addtime]
      ,[adduser]
      ,[procdeptid]
      ,[procdept]
      ,[procid]
      ,[procname]
      ,[procdate]
      ,[stepresult]
      ,[overresult]
      ,[typeid]
      ,[typename]
      ,[procphone]
  FROM  [MQ400Main] where mq4id='" + id+"'";
            DbSql dq = new DbSql();
            return dq.ExecuteQuery(sql);

        }

        public int deletemq400(string mq4id)
        {
            string sql = "delete FROM  [MQ400Main] where mq4id='" + mq4id + "'";
            DbSql dq = new DbSql();
            return dq.ExecuteSql(sql);
        
        }
    }
}
